package com.hopedove.quanlitycheck.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hopedove.quanlitycheck.R;
import com.hopedove.quanlitycheck.entity.XiaciInfo;

import java.util.List;

public class XcslAdapter extends BaseAdapter {

	private Context mContext;
	private onDeleteClickListener mOnDeleteClickListener;
	private onCounterClickListener mOnCounterClickListener;
	private List<XiaciInfo> mList;

	public XcslAdapter(Context context, List<XiaciInfo> list) {
		super();
		mContext = context;

		// 这里集合用=号赋值，改变内部productlist 外部list一样会变
		mList = list;

	}

	@Override
	public int getCount() {

		return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) { // 获得当前项的示例
		final XiaciInfo xcxx;
		xcxx = (XiaciInfo) getItem(position);
		View view;
		final ViewHolder viewholder;
		if (convertView == null) {
			view = LayoutInflater.from(mContext).inflate(R.layout.item_xc_list, parent, false);
			viewholder = new ViewHolder(view);
			view.setTag(viewholder);
		} else {
			view = convertView;
			viewholder = (ViewHolder) view.getTag();
		}

		viewholder.xcmcTv.setText(xcxx.getSJXMC());


		viewholder.xcslTv.setText(xcxx.getXCSL());


		viewholder.deleteBtn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// mClothList.remove(position);
				// ClothListAdapter.this.notifyDataSetChanged();
				if (mOnDeleteClickListener != null) {
					mOnDeleteClickListener.onClick(position);
				}

			}
		});

		viewholder.xcslTv.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				if (mOnCounterClickListener != null) {
					mOnCounterClickListener.onClick(position);
				}
			}
		});

		return view;

	}

	/**
	 * 设置删除接口
	 *
	 * @param onDeleteClickListener
	 */
	public void setOnDeleteClickListener(onDeleteClickListener onDeleteClickListener) {
		mOnDeleteClickListener = onDeleteClickListener;
	}

	/**
	 * 删除接口
	 *
	 * @author zhu_yu
	 */
	public interface onDeleteClickListener {
		public void onClick(int position);
	}


	/**
	 * 设置计数接口
	 *
	 * @param
	 */
	public void setOnCounterClickListener(onCounterClickListener onCounterClickListener) {
		mOnCounterClickListener = onCounterClickListener;
	}

	public interface onCounterClickListener {
		public void onClick(int position);
	}


	/**
	 * 对控件实例进行缓存
	 *
	 * @author zhu_yu
	 * @Description<功能详细描述>
	 * @Version [版本号, 2017-5-26]
	 */
	class ViewHolder {


		TextView xcmcTv;

		TextView xcslTv;

		LinearLayout deleteBtn;

		public ViewHolder(View view) {
			xcmcTv = (TextView) view.findViewById(R.id.xcmcTv);

			xcslTv = (TextView) view.findViewById(R.id.xcslTv);

			deleteBtn = (LinearLayout) view.findViewById(R.id.deleteBtn);

		}

	}

}
